<html>
<head>
    <style type="text/css">
        h2{
            font-size:30px;
            color: #006e99;
            text-align:center;
        }

        #center {
            margin: 0 auto;
            height: 500px;
            width: 700px;
            text-align: center;
            overflow: hidden;
            padding: 20px;

        }
        .input-group
        {
            padding:10px;
            font-size: 20px;
        }
        .baocun{
            background-color: #0bd54e;
            color: white;
            height: 35px;
            width: 85px;
            font-size: 15px;
        }
        .fanhui{
            background-color: #056bb0;
            color: white;
            height: 35px;
            width: 85px;
            font-size: 15px;
        }
        #ts{
            margin-right: -141px;
            color: red;
            font-size: 10px;
        }
    </style>
</head>
<body>
<div id="center">
    <h2 >修改信息</h2>
    <div class="input-group" >
		<span style="font-family: 楷体">
			用户名：
			<input  id="username" name="username" type="text" style="height:40px" value=""  autocomplete="off" readonly="readonly">
		</span><span id="ts">提示：用户名不可修改！</span>
    </div>
    <div class="input-group" >
		<span style="font-family: 楷体;" >
			姓&nbsp;&nbsp;名：
			<input  id="name" name="name" type="text" style="height:40px" value=""  autocomplete="off">
		</span>
    </div>


    <div class="input-group" >
		<span style="font-family: 楷体;">
			电&nbsp;&nbsp;话：
			<input  id="tel" name="tel" type="tel" style="height:40px" value=""  autocomplete="off">
		</span>
    </div>
    <div style="margin-top:20px">
        <input class="fanhui"  name="registerButton" id="register1" type="button" value="返回">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        <input class="baocun"  name="registerButton" id="register" type="button" value="保存">
    </div>
    </form>
</div>
<script src="bower_components/jquery/dist/jquery.min.js" ></script>
<script type="text/javascript">

    $(function (){
        doshujuObject()
    })
    $(function (){
        $(".fanhui").on("click",doFanhui)
    })
    function doFanhui(){
        let url="grxx-list"
        $("#mainContentId").load(url)

    }
    $(function (){
        $(".baocun").on("click",doBaocun)

    })
    //获取数据
    function doGetEditFormData(){
        var params={

            name:$("#name").val(),
            username:$("#username").val(),
            tel:$("#tel").val(),

        }
        return params;
    }

    function doBaocun(){
        //1.获取表单数据
        var params=doGetEditFormData();
        console.log(params)

        //2.异步提交表单数据(post)
        var url="/doUpdateUser"
        let requestMethod="post";
        $.post(url,params,function (result){
            if(result.state==1){
                            alert(result.message);
                            doCancel();
                        }else{
                            alert(result.message);
                        }
        })

    }
    //编辑页面cancel事件处理
    function doCancel(){
        //1.定义url
        var url="grxx-list";
        //2.异步加载列表页面
        $("#mainContentId").load(url);
    }
    function doshujuObject(){
        var username = $("#loginUserId").text();

        let url = 'findUserByUserName';
        let params='username='+username;
        $.ajax({
            url:url,
            data:params,
            success:function (result){
                doFindShuju(result.data)

            }
        });
        function doFindShuju(data){
            let input=$("#input-group")
            input.empty();
            for (let i=0;i<data.length;i++){
                doFindShujuRows(data[i])
                console.log(data[i])

            }

        }
        function doFindShujuRows(rows){
            console.log(rows)
            // $(this).val(""); //清空上次input框里的数据
            $("#name").val(rows.name);  //往input框里传值
            $("#username").val(rows.username);  //往input框里传值
            $("#tel").val(rows.tel);  //往input框里传值


        }
    }










</script>







</body>
</html>
